#----------------------------------------------------------------------------
# wxPita - wxPython wrapper library for painless layout and event binding
#
# Author:       Feihong Hsu
# Email:        hsu DOT feihong AT yahoo DOT com
# Website:      http://wxpita.googlecode.com/
# Created:      2007 Dec 15
# Copyright:    (c) 2007 by Feihong Hsu
# License:      BSD License
#----------------------------------------------------------------------------
import wx
import wx.calendar
import wx.grid
import wxaddons.sized_controls as sc
from core import WxWrapper, ContainerWrapper

# -----------------------------------------------------------------------------
# Container Widgets
# -----------------------------------------------------------------------------
Frame = ContainerWrapper(wx.Frame, 'title')
Panel = ContainerWrapper(wx.Panel)

class SizedFrameWrapper(ContainerWrapper):
    def set_widget_attributes(self):
        sizerType = self.args.get('sizerType', 'vertical')
        options = self.args.get('options', {})
        self.widget.GetContentsPane().SetSizerType(sizerType, options)
    
    def add_children(self):
        panel = self.widget.GetContentsPane()
        for child in self.children:
            child.CreateWidget(panel)
            child.widget.SetSizerProps(**child.args)

SizedFrame = SizedFrameWrapper(sc.SizedFrame, 'title')

class SizedPanelWrapper(ContainerWrapper):
    def set_widget_attributes(self):
        sizerType = self.args.get('sizerType', 'vertical')
        options = self.args.get('options', {})
        self.widget.SetSizerType(sizerType, options)
        
    def add_children(self):
        for child in self.children:
            child.CreateWidget(self.widget)
            child.widget.SetSizerProps(**child.args)
    
SizedPanel = SizedPanelWrapper(sc.SizedPanel)

class SplitterWindowWrapper(ContainerWrapper):
    def add_children(self):
        assert len(self.children) == 2
        
        w1, w2 = (c.CreateWidget(self.widget) for c in self.children)

        orient = self.args.get('orient', 'horizontal')
        sashPosition = int(self.args.get('sashPosition', 0))
        
        if orient == 'horizontal':
            self.widget.SplitHorizontally(w1, w2, sashPosition)
        else:
            self.widget.SplitVertically(w1, w2, sashPosition)

SplitterWindow = SplitterWindowWrapper(wx.SplitterWindow)

Menu = ContainerWrapper(wx.Menu, 'title')
MenuItem = ContainerWrapper(wx.MenuItem, 'text, helpString, kind') 
SashWindow = ContainerWrapper(wx.SashWindow)
ScrolledWindow = ContainerWrapper(wx.ScrolledWindow)
StaticBox = ContainerWrapper(wx.StaticBox, 'label')
ToolBar = ContainerWrapper(wx.ToolBar)

# -----------------------------------------------------------------------------
# Core Widgets
# -----------------------------------------------------------------------------
BitmapButton = WxWrapper(wx.BitmapButton, 'bitmap')
Button = WxWrapper(wx.Button, 'label')
CalendarCtrl = WxWrapper(wx.calendar.CalendarCtrl, 'date')
CheckBox = WxWrapper(wx.CheckBox, 'label')
CheckListBox = WxWrapper(wx.CheckListBox, 'choices')
Choice = WxWrapper(wx.Choice, 'choices')
ComboBox = WxWrapper(wx.ComboBox, 'choices')
DatePickerCtrl = WxWrapper(wx.DatePickerCtrl, 'dt')
Gauge = WxWrapper(wx.Gauge, 'range')
Grid = WxWrapper(wx.grid.Grid)
ListBox = WxWrapper(wx.ListBox, 'choices')
ListCtrl = WxWrapper(wx.ListCtrl)
RadioBox = WxWrapper(wx.RadioBox, 'label, choices, majorDimension')
RadioButton = WxWrapper(wx.RadioButton, 'label')
SearchCtrl = WxWrapper(wx.SearchCtrl, 'value')
Slider = WxWrapper(wx.Slider, 'minValue, maxValue')
SpinButton = WxWrapper(wx.SpinButton)
SpinCtrl = WxWrapper(wx.SpinCtrl, 'min, max, initial')
StaticBitmap = WxWrapper(wx.StaticBitmap, 'label')
StaticText = WxWrapper(wx.StaticText, 'label')
StatusBar = WxWrapper(wx.StatusBar)
TextCtrl = WxWrapper(wx.TextCtrl, 'value')
ToggleButton = WxWrapper(wx.ToggleButton, 'label')
TreeCtrl = WxWrapper(wx.TreeCtrl)